Unreal Engine 4.25.4 | 您所在的位置:网站首页 › ue4 createdefaultsubobject › Unreal Engine 4.25.4 |
I have the following actor: UCLASS() class X_API AMoveableRigidBodyActor : public AActor { GENERATED_BODY() public: // Sets default values for this actor's properties AMoveableRigidBodyActor(); public: UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Custom") USceneComponent* SceneComponent; UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Custom") UMoveableRigidBodyComponent* MoveableRigidBodyComponent; };This Actor makes a reference to a UMoveableRigidBodyComponent and a USceneComponent which I run CreateDefaultSubobject on and attach in the following fashion in the constructor: AMoveableRigidBodyActor::AMoveableRigidBodyActor() { SceneComponent = CreateDefaultSubobject(FName("AMoveableRigidBodyActor_SceneComponent")); SetRootComponent(SceneComponent); MoveableRigidBodyComponent = CreateDefaultSubobject(FName("AMoveableRigidBodyActor_MoveableRigidBodyComponent")); MoveableRigidBodyComponent->SetupAttachment(SceneComponent); }So far, so good. Now inside my UMoveableRigidBodyComponent I instantiate a few components that are relevant to that component. I expect these components to be visible and manageable from within my blueprint: UCLASS() class X_API UMoveableRigidBodyComponent : public USceneComponent { GENERATED_BODY() public: // Sets default values for this component's properties UMoveableRigidBodyComponent(); override; UPROPERTY(BlueprintReadOnly, EditAnywhere, Category = "Custom") USceneComponent* SceneComponent; UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Custom") UStaticMeshComponent* StaticMeshComponent; };Here I use CreateDefaultSuboject to attach everything to this component: UMoveableRigidBodyComponent::UMoveableRigidBodyComponent() { SceneComponent = CreateDefaultSubobject(FName("UMoveableRigidBodyComponent_SceneComponent")); SceneComponent->SetupAttachment(this); StaticMeshComponent = CreateDefaultSubobject(FName("UMoveableRigidBodyComponent_StaticMeshComponent")); StaticMeshComponent->SetupAttachment(SceneComponent); }So, all of this feels pretty normal so far. So I go into my editor, create a blueprint that’s based off of the AMoveableRigidBodyActor and I assign a static mesh to my component: ![]() Still good. But then I hit the compile button: ![]() The selected static mesh has now vanished from the editor but still seems to be filling the value correctly. Furthermore, if I put this into the game world you can see that the static mesh sure enough isn’t there in the instance: ![]() What am I misunderstanding here? |
CopyRight 2018-2019 实验室设备网 版权所有 |